import java.util.Stack;
//力扣 150. 逆波兰表达式求值
public class testwork1 {
    public int evalRPN(String[] tokens) {
        Stack<Integer> ret=new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String s=tokens[i];
            if(s.equals("+")||s.equals("-")||s.equals("*")||s.equals("/")){
                Integer temp2=ret.pop();//先取出来的值放运算符右边
                Integer temp1=ret.pop();
                switch (s){
                    case "+":ret.push(temp1+temp2);break;
                    case "-":ret.push(temp1-temp2);break;
                    case "*":ret.push(temp1*temp2);break;
                    case "/":ret.push(temp1/temp2);break;
                }
            }
            else{
                Integer temp=Integer.valueOf(s);
                ret.push(temp);
            }
        }
        return ret.peek();
    }
    public static void main(String[] args) {

    }
}
